package bbc;

import javax.swing.tree.TreeNode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeSet;

public class Main {
    public static class Node {
        int data;
        Node leftChild;
        Node rightChild;

        public Node(int  data) {
            this(data,null,null);
        }

        public Node(int data, Node leftChild, Node rightChild) {
            this.data = data;
            this.leftChild = leftChild;
            this.rightChild = rightChild;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int parseInt = Integer.parseInt(bf.readLine());
        int [][] num = new int[parseInt][2];
        for (int i = 0; i < parseInt; i++) {
            String[] s = bf.readLine().split(" ");
            num[i][0] = Integer.parseInt(s[0]);
            num[i][1] = Integer.parseInt(s[1]);
        }

        for (int i = 0; i < parseInt; i++) {
            int[] arr = new int[num[i][0]];
            for (int j = 0; j < num[i][0]; i++) {
                arr[j] = j+1;
            }
            Node completeTree = createCompleteTree(arr, 0);
            Node remove = remove(completeTree, num[i][1]);
            levelOrder(remove);
            System.out.println();
        }
    }

    //创建一颗完全二叉树
    public static Node createCompleteTree(int[] arr, int index) {
        Node newNode = null;
        //保证index不会越界
        if(index < arr.length){
            newNode  = new Node(arr[index]);
            newNode.leftChild = createCompleteTree(arr, 2 * index + 1);
            newNode.rightChild = createCompleteTree(arr, 2 * index + 2);
        }
        return newNode;
    }
    //移位
    public static Node remove(Node node, int num){

        Node cur = node;
        while(cur.leftChild != null){

        }
        return node;
    }

    //层序遍历
    public static void levelOrder(Node root) {
        LinkedList<Node> queue = new LinkedList<>();
        if(root != null){//如果根节点不为空,将第一层根节点入队列
            queue.addFirst(root);
        }
        while(!queue.isEmpty()){//只要队列不为空，执行循环
            int num = queue.size();//记录此时队列的长度，
            for(int i = 0; i < num; i++){//对某一层的所有节点进行操作(从左到右)
                Node Node = queue.removeFirst();//取出这一层第一个节点
                System.out.print(Node.data+" ");//打印节点
                if(Node.leftChild != null){//将此节点的左子树根节点入队列
                    queue.addLast(Node.leftChild);
                }
                if(Node.rightChild != null){//将此节点的右子树根节点入队列
                    queue.addLast(Node.rightChild);
                }
            }
        }
    }

}
